package net.toocruel.iqismart.entity.common;

import net.toocruel.iqismart.entity.base.BaseEntity;
import net.toocruel.iqismart.entity.constants.CategoryVisibility;
import net.toocruel.iqismart.entity.constants.ReviewStatus;
import net.toocruel.iqismart.entity.core.Answer;
import net.toocruel.iqismart.entity.core.Question;
import net.toocruel.iqismart.entity.rbac.Role;

import javax.persistence.*;
import java.util.Set;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/5/8 上午11:35
 */
@Entity
public class Category extends BaseEntity {
    private static final long serialVersionUID = 5778999752956705143L;
    @ManyToOne(cascade = CascadeType.DETACH)
    @JoinColumn(name = "parentId")
    private Category parent;
    private int grade;
    private String name;
    private String icon;
    private String slug;
    @ElementCollection
    @Column(name = "categotyVisibilityId")
    @JoinTable(name = "category_visibility",joinColumns = @JoinColumn(name = "categoryId"))
    private Set<CategoryVisibility> visibilities;
    private int sort;
    @ManyToMany(cascade = CascadeType.DETACH)
    @JoinTable(name = "category_role",joinColumns = @JoinColumn(name = "categoryId"),inverseJoinColumns = @JoinColumn(name = "roleId"))
    private Set<Role> roles;
    @Enumerated(EnumType.ORDINAL)
    private ReviewStatus status;
    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "parent")
    @OrderBy("id desc")
    private Set<Category> childs;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "category")
    @OrderBy("id desc")
    private Set<Question> questions;

    @OneToMany(cascade = CascadeType.DETACH,fetch = FetchType.LAZY,mappedBy = "category")
    @OrderBy("id desc")
    private Set<Tag> tags;

    public Set<Tag> getTags() {
        return tags;
    }

    public void setTags(Set<Tag> tags) {
        this.tags = tags;
    }

    public Set<Category> getChilds() {
        return childs;
    }

    public void setChilds(Set<Category> childs) {
        this.childs = childs;
    }

    public Category getParent() {
        return parent;
    }

    public void setParent(Category parent) {
        this.parent = parent;
    }

    public int getGrade() {
        return grade;
    }

    public void setGrade(int grade) {
        this.grade = grade;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getSlug() {
        return slug;
    }

    public void setSlug(String slug) {
        this.slug = slug;
    }



    public int getSort() {
        return sort;
    }

    public void setSort(int sort) {
        this.sort = sort;
    }

    public static long getSerialVersionUID() {
        return serialVersionUID;
    }

    public Set<CategoryVisibility> getVisibilities() {
        return visibilities;
    }

    public void setVisibilities(Set<CategoryVisibility> visibilities) {
        this.visibilities = visibilities;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public ReviewStatus getStatus() {
        return status;
    }

    public void setStatus(ReviewStatus status) {
        this.status = status;
    }
}
